package com.tang.controller;

import com.tang.dto.RoleListDto;
import com.tang.sys.ResponseResult;
import com.tang.sys.entity.Role;
import com.tang.sys.service.IMenuService;
import com.tang.sys.service.IRoleService;
import com.tang.sys.vo.AdminAddRoleVo;
import com.tang.sys.vo.MenuVo;
import com.tang.sys.vo.PageVo;
import com.tang.sys.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class AdminRoleController {

    @Autowired
    private IRoleService iRoleService;
    @Autowired
    private IMenuService iMenuService;

    @GetMapping("/list")
    public ResponseResult<PageVo> getAllRole(Integer pageNum, Integer pageSize, RoleListDto roleListDto){

        return iRoleService.getAllRole(pageNum,pageSize,roleListDto);
    }

    @PutMapping("/changeStatus")
    public ResponseResult<RoleVo> updateStatus(@RequestBody RoleVo roleVo){

        return iRoleService.updateStatus(roleVo);
    }



    //新增角色
    @PostMapping
    public ResponseResult addRoleMenu(@RequestBody Role role){
        iRoleService.addRoleMenu(role);
        return ResponseResult.okResult();
    }

    //删除角色和权限
    @DeleteMapping("{id}")
    public ResponseResult deleteRoleMenu(@PathVariable("id") Long id){

        return iRoleService.deleteRoleMenu(id);
    }

    //修改角色和权限
    @GetMapping("{id}")
    public ResponseResult getRoleById(@PathVariable("id") String id){

        return iRoleService.getRoleById(id);
    }

    //获取全部角色显示在用户
    @GetMapping("/listAllRole")
    public ResponseResult getListAllRole(){

        return iRoleService.getListAllRole();
    }

    //更新角色和菜单权限
    @PutMapping
    public ResponseResult updateRoleMenu(@RequestBody Role role){
        return iRoleService.updateRoleMenu(role);
    }
}
